/*
 * Copyright (C), 2017, 上海云首信息科技有限公司
 *
 * Author: 邓哲航
 * Date: 2018/5/17 上午12:53
 * History:
 * <author>    <time>    <version>    <desc>
 *
 */
package com.leaptocloud.easycloud.demo.filter;

import com.leaptocloud.easycloud.demo.shiro.XAuthToken;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;

/**
 * @author 邓哲航
 * @see
 * @since 2.3.8
 */
public class KeystoneAuthFilter implements ContainerRequestFilter {

    @Override
    public void filter(ContainerRequestContext containerRequestContext) {
        String xAuthToken = containerRequestContext.getHeaderString("X-Auth-Token");
        xAuthToken = "demo_user";
        Subject subject = SecurityUtils.getSubject();
        if (xAuthToken != null && !"".equals(xAuthToken) && !subject.isAuthenticated()) {
            XAuthToken token = new XAuthToken(xAuthToken);
            subject.login(token);
            System.out.println("filter login success!");
        }
    }


}
